<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/%E7%97%95%E8%BF%B9.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/%E7%97%95%E8%BF%B9.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.lug.ustc.edu.cn/css?family=Lato:300,300italic,400,400italic,700,700italic|Gabriola:300,300italic,400,400italic,700,700italic|Arial:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"tian_yu_ting.gitee.io","root":"/","scheme":"Gemini","version":"7.7.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="1、requests高级用法1、1  文件上传功能12345678import requests# 定义上传文件数据, 键为file, 值为文件句柄files &#x3D; &amp;#123;&#39;file&#39;: open(&#39;favicon.ico&#39;, &#39;rb&#39;)&amp;#125;r &#x3D; requests.post(&#39;http:&#x2F;&#x2F;httpbin.org&#x2F;post&#39;, files&#x3D;files)print(res.text)">
<meta property="og:type" content="website">
<meta property="og:title" content="requests高级部分 &amp; urllib简单介绍 &amp; 正则">
<meta property="og:url" content="https://tian_yu_ting.gitee.io/notes/spider/requests%E9%AB%98%E7%BA%A7%E9%83%A8%E5%88%86.html">
<meta property="og:site_name" content="Yu ting&#39;s blog">
<meta property="og:description" content="1、requests高级用法1、1  文件上传功能12345678import requests# 定义上传文件数据, 键为file, 值为文件句柄files &#x3D; &amp;#123;&#39;file&#39;: open(&#39;favicon.ico&#39;, &#39;rb&#39;)&amp;#125;r &#x3D; requests.post(&#39;http:&#x2F;&#x2F;httpbin.org&#x2F;post&#39;, files&#x3D;files)print(res.text)">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-04-05T15:41:21.139Z">
<meta property="article:modified_time" content="2020-04-05T15:41:21.139Z">
<meta property="article:author" content="Yu ting">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://tian_yu_ting.gitee.io/notes/spider/requests%E9%AB%98%E7%BA%A7%E9%83%A8%E5%88%86.html">

<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : false
  };
</script>

  
  
    <script src="/js/cursor/love.min.js"></script>
  

  <title>requests高级部分 & urllib简单介绍 & 正则 | Yu ting's blog
  </title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

  <script>
    var mobileBtn = function f() {
        var toggleMenu = document.getElementsByClassName("menu-toggle")[0];
        var mobileMenu = document.getElementById("mobile-menu");
        if(toggleMenu.classList.contains("active")){
           toggleMenu.classList.remove("active")
            mobileMenu.classList.remove("active")
        }else{
            toggleMenu.classList.add("active")
            mobileMenu.classList.add("active")
        }
    }
  </script>

   <!-- 不知道是什么玩意 -->
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
<link rel="alternate" href="/atom.xml" title="Yu ting's blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" style="background-image:url(/images/14.jpg);background-repeat:no-repeat;background-attachment: fixed;">


  <div class="container use-motion">
    <!-- 网页上方的黑色长线 -->
    <div class="headband"></div>
    
    <!-- 在首页添加github图标 -->
<!--     <a href="https://github.com/h4055874" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub">
      <svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path>
      </svg>
    </a>
      <style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style> -->
    <!--  -->

    <!-- -->

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Yu ting's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">I only for you!</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">66</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类<span class="badge">16</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">171</span></a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
        <!--
        <input id="switch_default" type="checkbox" class="switch_default">
        <label for="switch_default" class="toggleBtn"></label>
        -->
      </li>
  </ul>

<style>
    /*input css begin*/
*{
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}
/* input[type="checkbox"],input[type="radio"]{
    display: none;
    width: 0;
    height: 0;
    visibility: hidden;
} */
input[type="checkbox"]:checked + label:after{
    transition: all 0.3s ease-in;
}
input[type="checkbox"]:not(:checked) + label:after {
    transition: all 0.3s ease-out;
}
input[type="checkbox"]:checked + label,
input[type="checkbox"]:not(:checked) + label{
    transition: all 0.3s ease-in-out;
}
input[type="checkbox"]:checked + label:before,input[type="checkbox"]:checked + label i:before,input[type="checkbox"]:not(:checked) + label i:before,
input[type="checkbox"]:checked + label i:after,input[type="checkbox"]:not(:checked) + label i:after,input[type="checkbox"]:not(:checked) + label:before{
    transition: all 0.3s ease-in-out;
}
input[type="radio"]:checked + label:after,
input[type="radio"]:not(:checked) + label:after {
    transition: all 0.3s ease-in-out;
}
.switch_default[type="checkbox"]{
    display: none;
}
.switch_default + label{
     background-color: #e6e6e6;
     border-radius:7px;
     cursor: pointer;
     display: inline-block;
     height: 14px;
     position: relative;
     box-shadow: 0.2px 0.2px 1px 0.5px rgb(180,180,180);
     width: 30px;
 }
.switch_default + label:after{
    background-color: #fff;
    border-radius: 50%;
    content: "";
    height: 12px;
    left: 1px;
    position: absolute;
    top: .5px;
    width: 12px;
    box-shadow: 0.2px 0.2px 1px 0.5px rgb(180,180,180);
}
.switch_default:checked + label{
    background-color: #1ABC9C;
    box-shadow:none;
}
.switch_default:checked + label:after{
    left: 17px;
}
</style>
</nav>
  <div class="site-search">
    <div class="search-pop-overlay">
  <div class="popup search-popup">
      <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

  </div>
</div>

  </div>
</div>
    </header>

    <!-- -->
    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main class="main">
    <!--sm -->
      <div class="main-inner">
        <div class="content-wrap">
          
  
  


          <div class="content">
            

  <div class="posts-expand">
    
    
    
    <div class="post-block" lang="zh-CN">
      <header class="post-header">

<h1 class="post-title" itemprop="name headline">requests高级部分 & urllib简单介绍 & 正则
</h1>

<div class="post-meta">
  
  <ul class="breadcrumb">
          
            <li><a href="/notes/">NOTES</a></li>
            <li><a href="/notes/spider/">SPIDER</a></li>
            <li>REQUESTS高级部分</li>
          
  </ul>

</div>

</header>

      
      
      
      <div class="post-body">
          <h2 id="1、requests高级用法"><a href="#1、requests高级用法" class="headerlink" title="1、requests高级用法"></a>1、requests高级用法</h2><h2 id="1、1-文件上传功能"><a href="#1、1-文件上传功能" class="headerlink" title="1、1  文件上传功能"></a>1、1  文件上传功能</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"></span><br><span class="line"><span class="comment"># 定义上传文件数据, 键为file, 值为文件句柄</span></span><br><span class="line">files = &#123;</span><br><span class="line"><span class="string">'file'</span>: open(<span class="string">'favicon.ico'</span>, <span class="string">'rb'</span>)</span><br><span class="line">&#125;</span><br><span class="line">r = requests.post(<span class="string">'http://httpbin.org/post'</span>, files=files)</span><br><span class="line">print(res.text)</span><br></pre></td></tr></table></figure>

<h2 id="1、2-cookie处理"><a href="#1、2-cookie处理" class="headerlink" title="1、2  cookie处理"></a>1、2  cookie处理</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 手动处理cookie：</span></span><br><span class="line">	<span class="number">1.</span>headers添加cookie键值对</span><br><span class="line">	<span class="number">2.</span>RequestsCookieJar对象</span><br><span class="line"><span class="comment"># 自动处理cookie：Session</span></span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># headers内添加cookie键值对处理cookie</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line">headers = &#123;</span><br><span class="line">    <span class="string">'User-Agent'</span>:<span class="string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'</span>,</span><br><span class="line">    <span class="string">'Cookie'</span>:<span class="string">'BIDUPSID=E01FE1A1E9555174ABC136FBFBFDE674; PSTM=1575031812; BD_UPN=12314753; BAIDUID=580A55392F38BF9168294CCFB5F408C8:FG=1; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; yjs_js_security_passport=fed4dfca16fcc236aa3827bce130a90fcb7407bd_1576809267_js; COOKIE_SESSION=7114_0_9_7_8_5_0_0_9_3_0_0_7493_0_2_0_1576828833_0_1576828831%7C9%23951_22_1576726592%7C4; delPer=0; H_PS_PSSID=1458_21104_30211_30284_26350; BDUSS=VA4dG9aTExqY0ZsQkVPYkk2a3Z-TTlseWEteW9-ZkFZOHZ6TGZoN2VyRXVIU1JlRUFBQUFBJCQAAAAAAAAAAAEAAAB45WVmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC6Q~F0ukPxdd; BD_HOME=1'</span></span><br><span class="line">&#125;</span><br><span class="line">url = <span class="string">'https://www.baidu.com/'</span></span><br><span class="line">res = requests.get(url = url , headers = headers)</span><br><span class="line">res.encoding = <span class="string">'urf-8'</span></span><br><span class="line"><span class="keyword">with</span> open(<span class="string">'baidu_login.html'</span>,<span class="string">'w'</span>,encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> f:</span><br><span class="line">    f.write(res.text)</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># RequestsCookieJar对象处理cookie: 用cookie维持百度登陆</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line">headers = &#123;</span><br><span class="line"><span class="string">'User-Agent'</span>: <span class="string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'</span></span><br><span class="line">&#125;</span><br><span class="line">url = <span class="string">'https://www.baidu.com/'</span></span><br><span class="line">cookies = <span class="string">'BIDUPSID=E01FE1A1E9555174ABC136FBFBFDE674; PSTM=1575031812; BD_UPN=12314753; BAIDUID=580A55392F38BF9168294CCFB5F408C8:FG=1; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; yjs_js_security_passport=fed4dfca16fcc236aa3827bce130a90fcb7407bd_1576809267_js; COOKIE_SESSION=7114_0_9_7_8_5_0_0_9_3_0_0_7493_0_2_0_1576828833_0_1576828831%7C9%23951_22_1576726592%7C4; delPer=0; H_PS_PSSID=1458_21104_30211_30284_26350; BDUSS=VA4dG9aTExqY0ZsQkVPYkk2a3Z-TTlseWEteW9-ZkFZOHZ6TGZoN2VyRXVIU1JlRUFBQUFBJCQAAAAAAAAAAAEAAAB45WVmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC6Q~F0ukPxdd; BD_HOME=1'</span></span><br><span class="line">jar = requests.cookies.RequestsCookieJar()</span><br><span class="line"><span class="keyword">for</span> item <span class="keyword">in</span> cookies.split(<span class="string">';'</span>):</span><br><span class="line">    key,value = item.split(<span class="string">'='</span>,<span class="number">1</span>)</span><br><span class="line">    jar.set(key,value)</span><br><span class="line"></span><br><span class="line">res = requests.get(url = url , headers = headers , cookies = jar)</span><br><span class="line">res.encoding = <span class="string">'utf-8'</span></span><br><span class="line"><span class="keyword">with</span> open(<span class="string">'baidu.html'</span>,<span class="string">'w'</span>,encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> f:</span><br><span class="line">    f.write(res.text)	 <span class="comment"># 响应数据中包含用户名信息, 说明cookie生效</span></span><br></pre></td></tr></table></figure>

<h2 id="1、3-会话维持"><a href="#1、3-会话维持" class="headerlink" title="1、3  会话维持"></a>1、3  会话维持</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># HTTP无状态:</span></span><br><span class="line">	使用requests模块中的get()和post()方法请求网页时, 每一次请求都是独立的, 没有连续请求之间的状态保持. 假象, 如果你登陆了淘宝后向查看订单, 那么如果没有状态的维持就无法实现.</span><br><span class="line">    </span><br><span class="line"><span class="comment"># 会话的维持: Session对象</span></span><br><span class="line"><span class="keyword">from</span> requests <span class="keyword">import</span> Session</span><br><span class="line"></span><br><span class="line">url = <span class="string">'http://www.renren.com/ajaxLogin/login?1=1&amp;uniqueTimestamp=20191151116375'</span></span><br><span class="line">session = Session()</span><br><span class="line">headers = &#123;</span><br><span class="line">    <span class="string">'User-Agent'</span>: <span class="string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'</span></span><br><span class="line">&#125;</span><br><span class="line">data = &#123;</span><br><span class="line">    <span class="string">'email'</span>: <span class="string">'17679962330'</span>,</span><br><span class="line">    <span class="string">'icode'</span>: <span class="string">''</span>,</span><br><span class="line">    <span class="string">'origURL'</span>: <span class="string">'http://www.renren.com/home'</span>,</span><br><span class="line">    <span class="string">'domain'</span>: <span class="string">'renren.com'</span>,</span><br><span class="line">    <span class="string">'key_id'</span>: <span class="string">'1'</span>,</span><br><span class="line">    <span class="string">'captcha_type'</span>: <span class="string">'web_login'</span>,</span><br><span class="line">    <span class="string">'password'</span>: <span class="string">'4f099e818abe7310b77aa1b5f45e5e4084e4af309d90750e1d88bae39e85c828'</span>,</span><br><span class="line">    <span class="string">'rkey'</span>: <span class="string">'080f2e6d6b76e31a7ebc070c15096350'</span>,</span><br><span class="line">    <span class="string">'f'</span>: <span class="string">'http%3A%2F%2Fwww.renren.com%2F973125645%2Fnewsfeed%2Fphoto'</span>,</span><br><span class="line">&#125;</span><br><span class="line">res = session.post(url=url, headers=headers, data=data)</span><br><span class="line">ret = session.get(url=<span class="string">'http://www.renren.com/972036549/profile'</span>,data=data)</span><br><span class="line"><span class="keyword">with</span> open(<span class="string">'renren.html'</span>,<span class="string">'w'</span>,encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> f:</span><br><span class="line">    f.write(ret.text)</span><br></pre></td></tr></table></figure>

<h2 id="1、4-SSL证书验证"><a href="#1、4-SSL证书验证" class="headerlink" title="1、4  SSL证书验证"></a>1、4  SSL证书验证</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 1.SSL证书验证</span></span><br><span class="line">requests提供了证书验证的功能. 当发起HTTP请求时, 模块会检查SSL证书. 但检查的行为可以用verify参数来控制.</span><br><span class="line">	verify = <span class="literal">False</span>  <span class="comment"># 不检查SSL证书</span></span><br><span class="line">	verify = <span class="literal">True</span>  <span class="comment"># 检查SSL证书</span></span><br><span class="line">    </span><br><span class="line"><span class="comment"># 2.异常</span></span><br><span class="line">如果使用requests模块的SSL验证, 验证不通过会抛出异常, 此时可以将verify参数设置为<span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 3.https://www.tutumanhua.com的证书验证</span></span><br><span class="line"><span class="comment"># 会抛出异常	requests.exceptions.SSLError</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line">response = requests.get(<span class="string">'https://www.tutumanhua.com'</span>)</span><br><span class="line">print(response.status_code)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 不抛异常, 但会出现警告</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line">response = requests.get(<span class="string">'https://www.tutumanhua.com'</span>, verify=<span class="literal">False</span>)</span><br><span class="line">print(response.status_code)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 禁止警告</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"><span class="keyword">from</span> requests.packages <span class="keyword">import</span> urllib3</span><br><span class="line">urllib3.disable_warnings()</span><br><span class="line">response = requests.get(url=<span class="string">'https://www.tutumanhua.com'</span>, verify=<span class="literal">False</span>)</span><br><span class="line">print(response.status_code)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 最终版</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"></span><br><span class="line">headers = &#123;</span><br><span class="line">    <span class="string">'User-Agent'</span>: <span class="string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'</span>,</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">url = <span class="string">'https://www.tutumanhua.com'</span></span><br><span class="line">requests.packages.urllib3.disable_warnings() </span><br><span class="line">res = requests.get(url=url, headers=headers, verify=<span class="literal">False</span>)</span><br><span class="line">print(res.status_code)</span><br></pre></td></tr></table></figure>

<h2 id="1、5-代理设置"><a href="#1、5-代理设置" class="headerlink" title="1、5  代理设置"></a>1、5  代理设置</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 代理: 代理即代理ip</span></span><br><span class="line">代理ip是指在请求的过程中使用非本机ip进行请求, 避免大数据量频繁请求的过程中出现ip封禁, 限制数据的爬取.</span><br><span class="line"></span><br><span class="line"><span class="comment"># 代理ip分类:</span></span><br><span class="line">	<span class="number">1.</span>透明代理ip: 请求时, 服务器知道请求的真实ip, 知道请求使用了代理</span><br><span class="line">	<span class="number">2.</span>匿名代理ip: 请求时, 服务器知道请求使用了代理, 但不知道请求的真实ip</span><br><span class="line">	<span class="number">3.</span>高匿代理ip: 请求时, 服务器不知道请求使用了代理, 也不知道请求的真实ip</span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line">url = <span class="string">'https://www.baidu.com/s?ie=utf-8&amp;f=8&amp;rsv_bp=1&amp;rsv_idx=1&amp;tn=baidu&amp;wd=ip&amp;rsv_pq=a834758700059ab8&amp;rsv_t=60b33hUYnp%2F0I7P%2BFsy%2Fe0GZ9wIALM9f5WL12gftyn1dJvP7j9kOrAvyK7I&amp;rqlang=cn&amp;rsv_enter=1&amp;rsv_dl=tb&amp;rsv_sug3=3&amp;rsv_sug1=3&amp;rsv_sug7=101&amp;rsv_sug2=0&amp;prefixsug=ip&amp;rsp=2&amp;inputT=1808&amp;rsv_sug4=2550'</span></span><br><span class="line">headers = &#123;</span><br><span class="line">    <span class="string">'User-Agent'</span> : <span class="string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'</span></span><br><span class="line">&#125;</span><br><span class="line">proxies = &#123;</span><br><span class="line">    <span class="string">'https'</span> : <span class="string">'http://122.5.109.231:9999'</span>	<span class="comment"># 不管键是https，还是Http,后面的值都是http</span></span><br><span class="line">&#125;</span><br><span class="line">res = requests.get(url=url,headers=headers,proxies=proxies)</span><br><span class="line">res.encoding = <span class="string">'utf-8'</span></span><br><span class="line">print(res.text)</span><br></pre></td></tr></table></figure>

<h2 id="1、6-超时设置"><a href="#1、6-超时设置" class="headerlink" title="1、6  超时设置"></a>1、6  超时设置</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 超时设置:</span></span><br><span class="line">	由于网络状况的不同, 服务器配置差异以及服务器处理并发的能力不同, 有时会出现服务器的响应时间过长, 甚至无法获取响应而抛出异常. requests模块发送请求可以设置超时时间, 在超时时间内未得到响应, 便会抛出异常.</span><br><span class="line">    一方面, 减少了请求的阻塞时间, 一方面, 可以进行异常处理, 执行相应的操作.</span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"></span><br><span class="line">url = <span class="string">'https://www.baidu.com/'</span></span><br><span class="line">headers = &#123;</span><br><span class="line">    <span class="string">'User-Agent'</span>: <span class="string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">try</span>:</span><br><span class="line">    res = requests.get(url=url, headers=headers,timeout=<span class="number">0.1</span>)</span><br><span class="line">    res.encoding = <span class="string">'utf-8'</span></span><br><span class="line">    <span class="keyword">with</span> open(<span class="string">'baidu_1.html'</span>,<span class="string">'w'</span>,encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> f:</span><br><span class="line">        f.write(res.text)</span><br><span class="line"><span class="keyword">except</span> Exception <span class="keyword">as</span> e:</span><br><span class="line">    print(<span class="string">'爬取超时'</span>)</span><br></pre></td></tr></table></figure>

<h2 id="1、7-构建Request对象"><a href="#1、7-构建Request对象" class="headerlink" title="1、7  构建Request对象"></a>1、7  构建Request对象</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 1.Prepared Request</span></span><br><span class="line">利用 Prepared Request 数据结构构件Request对象. 其构建及使用步骤如下:</span><br><span class="line"><span class="keyword">from</span> requests <span class="keyword">import</span> Request, Session</span><br><span class="line"></span><br><span class="line"><span class="comment"># 构建Request对象</span></span><br><span class="line">url = <span class="string">'...'</span></span><br><span class="line">data = &#123;...</span><br><span class="line">&#125;</span><br><span class="line">params = &#123;...</span><br><span class="line">&#125;</span><br><span class="line">headers = &#123;...</span><br><span class="line">&#125;</span><br><span class="line">session = Session()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 构建post请求:</span></span><br><span class="line">req_post = Request(method=<span class="string">'POST'</span>, url=url, headers=headers, data=data)</span><br><span class="line">req_obj_post = session.prepare_request(req_post)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 构建get请求:</span></span><br><span class="line">req_get = Request(method=<span class="string">'GET'</span>, url=url, headers=headers, params=params)</span><br><span class="line">req_obj_get = session.prepare_request(req_get)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 利用构建的请求对象, 向服务器发送请求</span></span><br><span class="line">res = session.send(req_obj_post)</span><br><span class="line">res = session.send(req_obj_get)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 应用:</span></span><br><span class="line">通过此方法, 我们可以构建一个独立的request对象, 当需要请求的url很多时, 我们可以为每一个url构建一个request对象, 将所有request对象置于队列中, 便于调度.</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 构建request对象, 请求糗事百科获取页面</span></span><br><span class="line"><span class="keyword">from</span> requests <span class="keyword">import</span> Request, Session</span><br><span class="line">url = <span class="string">'https://www.qiushibaike.com/'</span></span><br><span class="line">headers = &#123;</span><br><span class="line">    <span class="string">"User-Agent"</span>:<span class="string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36'</span></span><br><span class="line">&#125;</span><br><span class="line">session = Session()</span><br><span class="line">req_get = Request(url=url, headers=headers, method=<span class="string">'GET'</span>)</span><br><span class="line">req_get_obj = session.prepare_request(req_get)</span><br><span class="line">res = session.send(req_get_obj)</span><br><span class="line">res.encoding = <span class="string">'utf-8'</span></span><br><span class="line"><span class="keyword">with</span> open(<span class="string">'qb_reqobj.html'</span>, <span class="string">'w'</span>, encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> f:</span><br><span class="line">    f.write(res.text)</span><br></pre></td></tr></table></figure>

<h2 id="2、urllib简单介绍"><a href="#2、urllib简单介绍" class="headerlink" title="2、urllib简单介绍"></a>2、urllib简单介绍</h2><p>　　1.urllib模块是Python的一个请求模块<br>　　2.Python2中是urllib和urllib2相结合实现请求的发送. Python3中同一为urllib库<br>　　3.urllib是Python内置的请求库, 其包含4个模块:<br>　　　　(1).request模块: 模拟发送请求<br>　　　　(2).error模块: 异常处理模块<br>　　　　(3).parse模块: 工具模块, 提供关于URL的处理方法, 如拆分, 解析, 合并等<br>　　　　(4).robotparser模块: 识别robots协议</p>
<h2 id="3-正则"><a href="#3-正则" class="headerlink" title="3.正则"></a>3.正则</h2><h2 id="3、1-元字符匹配"><a href="#3、1-元字符匹配" class="headerlink" title="3、1  元字符匹配"></a>3、1  元字符匹配</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">.     匹配任意字符，除了换行符</span><br><span class="line"></span><br><span class="line">[]    用来表示一组字符,单独列出：[abc] 匹配 <span class="string">'a'</span>，<span class="string">'b'</span>或<span class="string">'c'</span></span><br><span class="line"></span><br><span class="line">[^...]	匹配除了字符组中字符的所有字符</span><br><span class="line"></span><br><span class="line">\d    匹配任意数字，等价于 [<span class="number">0</span><span class="number">-9</span>].</span><br><span class="line"></span><br><span class="line">\D    匹配任意非数字</span><br><span class="line"></span><br><span class="line">\w    匹配字母数字及下划线</span><br><span class="line"></span><br><span class="line">\W    匹配非字母数字及下划线</span><br><span class="line"></span><br><span class="line">\s    匹配任意空白字符，等价于 [\t\n\r\f].</span><br><span class="line"></span><br><span class="line">\S    匹配任意非空字符</span><br></pre></td></tr></table></figure>

<h2 id="3、2-字符组-要求在一个位置匹配的字符可能出现很多种情况-各种情况组成一个组"><a href="#3、2-字符组-要求在一个位置匹配的字符可能出现很多种情况-各种情况组成一个组" class="headerlink" title="3、2  字符组: 要求在一个位置匹配的字符可能出现很多种情况, 各种情况组成一个组"></a>3、2  字符组: 要求在一个位置匹配的字符可能出现很多种情况, 各种情况组成一个组</h2><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[<span class="number">0123456789</span>]: 匹配<span class="number">0</span>到<span class="number">9</span>任意字符</span><br><span class="line">[<span class="number">0</span><span class="number">-9</span>]: 同上</span><br><span class="line">[a-z]: 匹配a到z的任意小写字母</span><br><span class="line">[A-Z]: 匹配A到Z的任意大写字母</span><br><span class="line">[<span class="number">0</span><span class="number">-9</span>a-fA-F]: 以上三种的组合, 匹配<span class="number">0</span><span class="number">-9</span>任意数组或a到f之间任意字母, 不区分大小写</span><br><span class="line">自定义字符组:[a3h5]  ---&gt;  代表匹配a, 3, h, 5等字符</span><br></pre></td></tr></table></figure>

<h2 id="3、3-量词"><a href="#3、3-量词" class="headerlink" title="3、3  量词:"></a>3、3  量词:</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">*  		重复零次或更多次</span><br><span class="line">+		重复一次或更多次</span><br><span class="line">?		重复零次或一次</span><br><span class="line">&#123;n&#125;		重复n次</span><br><span class="line">&#123;n,&#125;	重复n次或更多次</span><br><span class="line">&#123;n,m&#125;	重复n到m次</span><br></pre></td></tr></table></figure>

<h2 id="3、4-边界修饰符"><a href="#3、4-边界修饰符" class="headerlink" title="3、4  边界修饰符"></a>3、4  边界修饰符</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">^		匹配开始</span><br><span class="line">$		匹配结尾</span><br></pre></td></tr></table></figure>

<h2 id="3、5-分组"><a href="#3、5-分组" class="headerlink" title="3、5  分组"></a>3、5  分组</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">在正则表达式中添加(), 就形成了一个分组, 在re模块中优先匹配显示分组内容</span><br><span class="line"><span class="keyword">import</span> re</span><br><span class="line">s = <span class="string">"&lt;a href='www.baidu.com'&gt;正则匹配实验&lt;/a&gt;"</span></span><br><span class="line">res = re.findall(<span class="string">"href='(.*)'&gt;"</span>, s)</span><br><span class="line">print(res)</span><br></pre></td></tr></table></figure>

<h2 id="3、6-匹配模式"><a href="#3、6-匹配模式" class="headerlink" title="3、6  匹配模式"></a>3、6  匹配模式</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">re.S  单行模式</span><br><span class="line">re.M  多行模式	</span><br><span class="line">re.I   忽略大小写</span><br></pre></td></tr></table></figure>

<h2 id="3、7-婪匹配与非贪婪匹配"><a href="#3、7-婪匹配与非贪婪匹配" class="headerlink" title="3、7  婪匹配与非贪婪匹配"></a>3、7  婪匹配与非贪婪匹配</h2><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">贪婪匹配是指: 在使用量词:  * ,  +  等时, 尽可能多的匹配内容</span><br><span class="line">非贪婪匹配是指: 使用?对正则表达式进行修饰, 使量词的匹配尽可能少, 如+代表匹配1次或多次, 在?的修饰下, 只匹配1次.</span><br></pre></td></tr></table></figure>

<h2 id="3、8-re模块"><a href="#3、8-re模块" class="headerlink" title="3、8  re模块"></a>3、8  re模块</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>re.findall(<span class="string">'正则表达式'</span>, <span class="string">'待匹配字符串'</span>): 以列表形式返回所有满足匹配条件的结果, </span><br><span class="line"><span class="number">2.</span>re.search(<span class="string">'正则表达式'</span>, <span class="string">'带匹配字符串'</span>): 匹配到第一个就返回一个对象, 该对象使用group()进行取值, 如果未匹配到则返回<span class="literal">None</span></span><br><span class="line"><span class="number">3.</span>re.match(<span class="string">'正则表达式'</span>, <span class="string">'待匹配字符串'</span>): 从字符串开头进行匹配, 如果匹配成功返回一个对象,同样使用group()进行取值, 匹配不成功返回<span class="literal">None</span></span><br><span class="line"><span class="number">4.</span>re.compile(<span class="string">'正则表达式'</span>): 将正则表达式编译为对象, 但需要按该正则表达式匹配是可以在直接使用该对象调用以上方法即可.</span><br></pre></td></tr></table></figure>

<h2 id="3、9-利用正则表达式抓取图片"><a href="#3、9-利用正则表达式抓取图片" class="headerlink" title="3、9  利用正则表达式抓取图片"></a>3、9  利用正则表达式抓取图片</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 请求url, 抓取页面</span></span><br><span class="line">url = <span class="string">'http://www.win4000.com/zt/gaoqing.html'</span></span><br><span class="line"></span><br><span class="line">headers = &#123;</span><br><span class="line">    <span class="string">'User-Agent'</span>: <span class="string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'</span></span><br><span class="line">&#125;</span><br><span class="line">res = requests.get(url=url, headers=headers)</span><br><span class="line"><span class="comment"># 利用正则匹配页面中的img标签, 获取其src属性值</span></span><br><span class="line">ret = re.findall(<span class="string">r'&lt;ul class="clearfix"&gt;.*?&lt;/ul&gt;'</span>,res.text,re.S)[<span class="number">1</span>]</span><br><span class="line">url1 = re.findall(<span class="string">r'http://pic1.win4000.com/.*?\.jpg'</span>,ret)</span><br><span class="line"><span class="comment"># 遍历获取到的图片连接, 处理连接为完整的url, 再次请求抓取图片二进制流数据, 写入文件</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> url1:</span><br><span class="line">    content = requests.get(url=url,headers=headers).content</span><br><span class="line">    name = i.split(<span class="string">'/'</span>)[<span class="number">-1</span>]</span><br><span class="line">    print(name)</span><br><span class="line">    <span class="keyword">with</span> open(<span class="string">'./imgs/%name'</span> % name,<span class="string">'wb'</span>) <span class="keyword">as</span> f:</span><br><span class="line">        f.write(content)</span><br></pre></td></tr></table></figure>

      </div>
      
      
      
    </div>
    
  <ul class="breadcrumb">
          
            <li><a href="/notes/">NOTES</a></li>
            <li><a href="/notes/spider/">SPIDER</a></li>
            <li>REQUESTS高级部分</li>
          
  </ul>

    
    
    
  </div>


              <!-- 此处可在文章模块中间添加东西 -->
          </div>
          <!-- 评论系统 -->
          <!--
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
-->
        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、requests高级用法"><span class="nav-text">1、requests高级用法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、1-文件上传功能"><span class="nav-text">1、1  文件上传功能</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、2-cookie处理"><span class="nav-text">1、2  cookie处理</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、3-会话维持"><span class="nav-text">1、3  会话维持</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、4-SSL证书验证"><span class="nav-text">1、4  SSL证书验证</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、5-代理设置"><span class="nav-text">1、5  代理设置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、6-超时设置"><span class="nav-text">1、6  超时设置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、7-构建Request对象"><span class="nav-text">1、7  构建Request对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、urllib简单介绍"><span class="nav-text">2、urllib简单介绍</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-正则"><span class="nav-text">3.正则</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、1-元字符匹配"><span class="nav-text">3、1  元字符匹配</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、2-字符组-要求在一个位置匹配的字符可能出现很多种情况-各种情况组成一个组"><span class="nav-text">3、2  字符组: 要求在一个位置匹配的字符可能出现很多种情况, 各种情况组成一个组</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、3-量词"><span class="nav-text">3、3  量词:</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、4-边界修饰符"><span class="nav-text">3、4  边界修饰符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、5-分组"><span class="nav-text">3、5  分组</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、6-匹配模式"><span class="nav-text">3、6  匹配模式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、7-婪匹配与非贪婪匹配"><span class="nav-text">3、7  婪匹配与非贪婪匹配</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、8-re模块"><span class="nav-text">3、8  re模块</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、9-利用正则表达式抓取图片"><span class="nav-text">3、9  利用正则表达式抓取图片</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Yu ting"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">Yu ting</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">171</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">16</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">66</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/yourname" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yourname" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://mail.google.com/mail/u/0/#inbox" title="E-Mail → https:&#x2F;&#x2F;mail.google.com&#x2F;mail&#x2F;u&#x2F;0&#x2F;#inbox" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/u/6207787940" title="Weibo → https:&#x2F;&#x2F;weibo.com&#x2F;u&#x2F;6207787940" rel="noopener" target="_blank"><i class="fa fa-fw fa-weibo"></i>Weibo</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://news.google.com/?hl=zh-HK&gl=HK&ceid=HK%253Azh-Hant" title="Google → https:&#x2F;&#x2F;news.google.com&#x2F;?hl&#x3D;zh-HK&amp;gl&#x3D;HK&amp;ceid&#x3D;HK%3Azh-Hant" rel="noopener" target="_blank"><i class="fa fa-fw fa-google"></i>Google</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://v3u.cn/" title="https:&#x2F;&#x2F;v3u.cn&#x2F;" rel="noopener" target="_blank">刘悦的技术博客</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://www.missbless.cn/" title="http:&#x2F;&#x2F;www.missbless.cn&#x2F;" rel="noopener" target="_blank">ISSAC　LOVELESS</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://www.f322.xyz/" title="https:&#x2F;&#x2F;www.f322.xyz&#x2F;" rel="noopener" target="_blank">逆の神様</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://www.wosowoso.com/" title="http:&#x2F;&#x2F;www.wosowoso.com&#x2F;" rel="noopener" target="_blank">素材网</a>
        </li>
    </ul>
  </div>

      </div>
      <div style="width:220px;text-align:center;padding-top:10px;margin-bottom:10px;border-bottom:1px dotted #000;"></div>
      <!-- 数字时钟 -->
      <!-- canvas粒子时钟 https://www.cnblogs.com/xiaohuochai/p/6368039.html
  https://www.html5tricks.com/html5-canvas-dance-time.html
 -->
<div id="">
  <canvas id="canvas" style="width:60%;">
</div>
<script>
(function(){
  var WINDOW_WIDTH = 820;
        var WINDOW_HEIGHT = 250;
        var RADIUS = 7; //球半径
        var NUMBER_GAP = 10; //数字之间的间隙
        var u=0.65; //碰撞能量损耗系数
        var context; //Canvas绘制上下文
        var balls = []; //存储彩色的小球
        const colors = ["#33B5E5","#0099CC","#AA66CC","#9933CC","#99CC00","#669900","#FFBB33","#FF8800","#FF4444","#CC0000"]; //彩色小球的颜色
        var currentNums = []; //屏幕显示的8个字符
        var digit =
                  [
                      [
                          [0,0,1,1,1,0,0],
                          [0,1,1,0,1,1,0],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,0,1,1,0],
                          [0,0,1,1,1,0,0]
                      ],//0
                      [
                          [0,0,0,1,1,0,0],
                          [0,1,1,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [1,1,1,1,1,1,1]
                      ],//1
                      [
                          [0,1,1,1,1,1,0],
                          [1,1,0,0,0,1,1],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,1,1,0],
                          [0,0,0,1,1,0,0],
                          [0,0,1,1,0,0,0],
                          [0,1,1,0,0,0,0],
                          [1,1,0,0,0,0,0],
                          [1,1,0,0,0,1,1],
                          [1,1,1,1,1,1,1]
                      ],//2
                      [
                          [1,1,1,1,1,1,1],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,1,1,0],
                          [0,0,0,1,1,0,0],
                          [0,0,1,1,1,0,0],
                          [0,0,0,0,1,1,0],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,1,1,1,0]
                      ],//3
                      [
                          [0,0,0,0,1,1,0],
                          [0,0,0,1,1,1,0],
                          [0,0,1,1,1,1,0],
                          [0,1,1,0,1,1,0],
                          [1,1,0,0,1,1,0],
                          [1,1,1,1,1,1,1],
                          [0,0,0,0,1,1,0],
                          [0,0,0,0,1,1,0],
                          [0,0,0,0,1,1,0],
                          [0,0,0,1,1,1,1]
                      ],//4
                      [
                          [1,1,1,1,1,1,1],
                          [1,1,0,0,0,0,0],
                          [1,1,0,0,0,0,0],
                          [1,1,1,1,1,1,0],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,1,1,1,0]
                      ],//5
                      [
                          [0,0,0,0,1,1,0],
                          [0,0,1,1,0,0,0],
                          [0,1,1,0,0,0,0],
                          [1,1,0,0,0,0,0],
                          [1,1,0,1,1,1,0],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,1,1,1,0]
                      ],//6
                      [
                          [1,1,1,1,1,1,1],
                          [1,1,0,0,0,1,1],
                          [0,0,0,0,1,1,0],
                          [0,0,0,0,1,1,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,1,1,0,0,0],
                          [0,0,1,1,0,0,0],
                          [0,0,1,1,0,0,0],
                          [0,0,1,1,0,0,0]
                      ],//7
                      [
                          [0,1,1,1,1,1,0],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,1,1,1,0],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,1,1,1,0]
                      ],//8
                      [
                          [0,1,1,1,1,1,0],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,1,0,1,1],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,1,1,0],
                          [0,0,0,1,1,0,0],
                          [0,1,1,0,0,0,0]
                      ],//9
                      [
                          [0,0,0,0],
                          [0,0,0,0],
                          [0,1,1,0],
                          [0,1,1,0],
                          [0,0,0,0],
                          [0,0,0,0],
                          [0,1,1,0],
                          [0,1,1,0],
                          [0,0,0,0],
                          [0,0,0,0]
                      ]//:
                  ];

        function drawDatetime(cxt){
            var nums = [];

            context.fillStyle="#005eac"
            var date = new Date();
            var offsetX = 70, offsetY = 30;
            var hours = date.getHours();
            var num1 = Math.floor(hours/10);
            var num2 = hours%10;
            nums.push({num: num1});
            nums.push({num: num2});
            nums.push({num: 10}); //冒号
            var minutes = date.getMinutes();
            var num1 = Math.floor(minutes/10);
            var num2 = minutes%10;
            nums.push({num: num1});
            nums.push({num: num2});
            nums.push({num: 10}); //冒号
            var seconds = date.getSeconds();
            var num1 = Math.floor(seconds/10);
            var num2 = seconds%10;
            nums.push({num: num1});
            nums.push({num: num2});

            for(var x = 0;x<nums.length;x++){
                nums[x].offsetX = offsetX;
                offsetX = drawSingleNumber(offsetX,offsetY, nums[x].num,cxt);
                //两个数字连一块，应该间隔一些距离
                if(x<nums.length-1){
                    if((nums[x].num!=10) &&(nums[x+1].num!=10)){
                        offsetX+=NUMBER_GAP;
                    }
                }
            }

            //说明这是初始化
            if(currentNums.length ==0){
                currentNums = nums;
            }else{
                //进行比较
                for(var index = 0;index<currentNums.length;index++){
                    if(currentNums[index].num!=nums[index].num){
                        //不一样时，添加彩色小球
                        addBalls(nums[index]);
                        currentNums[index].num=nums[index].num;
                    }
                }
            }
            renderBalls(cxt);
            updateBalls();

            return date;
        }

        function addBalls (item) {
            var num = item.num;
            var numMatrix = digit[num];
            for(var y = 0;y<numMatrix.length;y++){
                for(var x = 0;x<numMatrix[y].length;x++){
                    if(numMatrix[y][x]==1){
                        var ball={
                            offsetX:item.offsetX+RADIUS+RADIUS*2*x,
                            offsetY:30+RADIUS+RADIUS*2*y,
                            color:colors[Math.floor(Math.random()*colors.length)],
                            g:1.5+Math.random(),
                            vx:Math.pow(-1, Math.ceil(Math.random()*10))*4+Math.random(),
                            vy:-5
                        }
                        balls.push(ball);
                    }
                }
            }
        }

        function renderBalls(cxt){
            for(var index = 0;index<balls.length;index++){
                cxt.beginPath();
                cxt.fillStyle=balls[index].color;
                cxt.arc(balls[index].offsetX, balls[index].offsetY, RADIUS, 0, 2*Math.PI);
                cxt.fill();
            }
        }

        function updateBalls () {
            var i =0;
            for(var index = 0;index<balls.length;index++){
                var ball = balls[index];
                ball.offsetX += ball.vx;
                ball.offsetY += ball.vy;
                ball.vy+=ball.g;
                if(ball.offsetY > (WINDOW_HEIGHT-RADIUS)){
                    ball.offsetY= WINDOW_HEIGHT-RADIUS;
                    ball.vy=-ball.vy*u;
                }
                if(ball.offsetX>RADIUS&&ball.offsetX<(WINDOW_WIDTH-RADIUS)){

                    balls[i]=balls[index];
                    i++;
                }
            }
            //去除出边界的球
            for(;i<balls.length;i++){
                balls.pop();
            }
        }
        function drawSingleNumber(offsetX, offsetY, num, cxt){
            var numMatrix = digit[num];
            for(var y = 0;y<numMatrix.length;y++){
                for(var x = 0;x<numMatrix[y].length;x++){
                    if(numMatrix[y][x]==1){
                        cxt.beginPath();
                        cxt.arc(offsetX+RADIUS+RADIUS*2*x,offsetY+RADIUS+RADIUS*2*y,RADIUS,0,2*Math.PI);
                        cxt.fill();
                    }
                }
            }
            cxt.beginPath();
            offsetX += numMatrix[0].length*RADIUS*2;
            return offsetX;
        }

        var canvas = document.getElementById("canvas");
        canvas.width=WINDOW_WIDTH;
        canvas.height=WINDOW_HEIGHT;
        context = canvas.getContext("2d");

        //记录当前绘制的时刻
        var currentDate = new Date();

        setInterval(function(){
            //清空整个Canvas，重新绘制内容
            context.clearRect(0, 0, context.canvas.width, context.canvas.height);
            drawDatetime(context);
        }, 50)
})();
</script>

      <!-- 建站时间 -->
      
      
      <!-- 音乐 -->
<!--       <div>
        <audio src="/images/林俊杰 - 对的时间点.flac" autoplay="autoplay" controls="controls" loop="loop"></audio>
        
          <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=298 height=52 src="//music.163.com/outchain/player?type=2&id=569213220&auto=1&height=32"></iframe>
         
      </div> -->
    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heartbeat" style="color:red"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Yu ting</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">420k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">6:22</span>
</div>
  <div class="powered-by"><a href="https://weibo.com/u/3035313940" class="theme-link" rel="noopener" target="_blank">Only丶Nie</a>
  </div>
  <span class="post-meta-divider">|</span>
  <div class="powered-by"><a href="https://weibo.com/u/6207787940" class="theme-link" rel="noopener" target="_blank">余生有你才安好丶</a>
  </div>

        
<div class="busuanzi-count">
  <script async src="/js/busuanzi.js"></script>
  <!-- https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js -->
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>总访问人数：
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>人
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>总访问量：
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>次
      </span>
    </span>
</div>







      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>


  <script defer src="/lib/three/three.min.js"></script>


  



  <script>
  if (CONFIG.page.isPost) {
    wpac_init = window.wpac_init || [];
    wpac_init.push({
      widget: 'Rating',
      id    : 24337,
      el    : 'wpac-rating',
      color : 'fc6423'
    });
    (function() {
      if ('WIDGETPACK_LOADED' in window) return;
      WIDGETPACK_LOADED = true;
      var mc = document.createElement('script');
      mc.type = 'text/javascript';
      mc.async = true;
      mc.src = '//embed.widgetpack.com/widget.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(mc, s.nextSibling);
    })();
  }
  </script>

  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'usjRVOXqGpbFIevxocLk2MXI-gzGzoHsz',
      appKey     : 'xd98ffpeQETblJ8uuGPacjjS',
      placeholder: "请在此处填写评论",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : true,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>


  <!-- 动画效果 -->
  

    <!-- 鼠标跟随 -->
  
  <!-- 鼠标指针 -->
  <style>
    body{cursor:url(/images/正常选择.cur),move}
    a{cursor:url(/images/链接选择.cur),wait} 
  </style>

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/koharu.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"log":false});</script></body>
</html>
